<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料编号">
              <a-input placeholder="请输入物料编号" v-model="queryParam.materialNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料描述">
              <a-input placeholder="请输入物料描述" v-model="queryParam.materialDesc"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('工艺物料')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <div  style="float: right">
          <a-checkbox style="color: #1890FF;margin-right: 12px" :checked="sameCheck" @change="sameCheckChang">同单据批量选中</a-checkbox>
          <a-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <a-col :span="6"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type="setting" />自定义列</a>
          </a-popover>
        </div>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onSelect: onSelect, onSelectAll:onSelectAll}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="materialDesc" slot-scope="text, record">
          <j-ellipsis :value="text" :length="14"/>
        </template>
        <template slot="materialNo" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <template slot="routeDesc" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <template slot="mould" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <mdm-process-route-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MdmProcessRouteModal from './modules/MdmProcessRouteModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "MdmProcessRouteDetailList",
    mixins:[JeecgListMixin],
    components: {
      MdmProcessRouteModal
    },
    data () {
      return {
        description: '工艺路线管理页面',
        // 表头
        columns: [
          {
            title:'物料编号',
            align:"center",
            sorter: true,
            dataIndex: 'materialNo'
          },
          {
            title:'物料描述',
            align:"center",
            dataIndex: 'materialDesc'
          },
          {
            title:'序号',
            align:"center",
            sorter: true,
            dataIndex: 'seqNo'
          },
          {
            title:'工序名称',
            align:"center",
            dataIndex: 'processName'
          },
          {
            title:'车间',
            align:"center",
            sorter: true,
            dataIndex: 'workshop'
          },
          {
            title:'工作中心',
            align:"center",
            sorter: true,
            dataIndex: 'workId_dictText'
          },
          {
            title:'标准工时',
            align:"center",
            sorter: true,
            dataIndex: 'standardHours'
          },
          {
            title:'准备工时',
            align:"center",
            sorter: true,
            dataIndex: 'prepareHours'
          },
          {
            title:'等待工时',
            align:"center",
            sorter: true,
            dataIndex: 'waitHours'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit_dictText'
          },
          {
            title:'要求说明',
            align:"center",
            dataIndex: 'routeDesc'
          },
          {
            title:'计价类型',
            align:"center",
            sorter: true,
            dataIndex: 'priceType_dictText'
          },
          {
            title:'模具/工装',
            align:"center",
            dataIndex: 'mould'
          },
          {
            title:'工序控制码',
            align:"center",
            sorter: true,
            dataIndex: 'controlCode'
          },
          {
            title:'工序控制描述',
            align:"center",
            dataIndex: 'controlDesc'
          },
          {
            title:'操作者',
            align:"center",
            sorter: true,
            dataIndex: 'handler'
          },
          {
            title:'生效标志',
            align:"center",
            sorter: true,
            dataIndex: 'effectFlag',
            customRender: (text) => (!text ? "" : (text == [1,0][0] ? "是" : "否"))
          },
          {
            title:'生效日期',
            align:"center",
            sorter: true,
            dataIndex: 'effectDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'工厂',
            align:"center",
            sorter: true,
            dataIndex: 'factory_dictText'
          },
          {
            title:'工艺版本',
            align:"center",
            dataIndex: 'processVersion'
          },
          {
            title:'工艺路径',
            align:"center",
            dataIndex: 'processDesc'
          },
          {
            title:'创建人',
            align:"center",
            sorter: true,
            dataIndex: 'createBy_dictText'
          },
          {
            title:'创建时间',
            align:"center",
            sorter: true,
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>19?text.substr(0,19):text)
            }
          },
          {
            title:'所属部门',
            align:"center",
            sorter: true,
            dataIndex: 'sysOrgCode_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/mdm/processRoute/detailPageList",
          delete: "/mdm/processRoute/delete",
          deleteBatch: "/mdm/processRoute/deleteBatch",
          exportXlsUrl: "/mdm/processRoute/exportXls",
          importExcelUrl: "mdm/processRoute/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        sameCheck: false,
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
         fieldList.push({type:'string',value:'materialNo',text:'物料编号',dictCode:''})
         fieldList.push({type:'popup',value:'materialDesc',text:'物料描述', popup:{code:'mdm_popup_bom_material',field:'material_id',orgFields:'material_id',destFields:'material_id'}})
         fieldList.push({type:'string',value:'processVersion',text:'工艺版本',dictCode:''})
         fieldList.push({type:'string',value:'factory',text:'工厂',dictCode:'mdm_factory,factory_name,id'})
         fieldList.push({type:'string',value:'processDesc',text:'工艺路径',dictCode:''})
         fieldList.push({type:'switch',value:'effectFlag',text:'生效标志'})
         fieldList.push({type:'date',value:'effectDate',text:'生效日期'})
         fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
         fieldList.push({type:'date',value:'createTime',text:'创建时间'})
         fieldList.push({type:'string',value:'updateBy',text:'修改人',dictCode:''})
         fieldList.push({type:'date',value:'updateTime',text:'修改时间'})
         fieldList.push({type:'string',value:'sysOrgCode',text:'所属部门',dictCode:''})
        this.superFieldList = fieldList
      },
      sameCheckChang(e){
        this.sameCheck = e.target.checked;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>